{% extends 'app01/admin/home.html' %}

{% block content %}


    <div class="panel panel-default">
        <div class="panel-heading">上传文件</div>
        <div class="panel-body">
            <div class="container">
                <div class="row">
                    <div class="col-md-6 col-md-offset-3">

                        文件名：
                        <input type="text" id="name_id" class="form-control">
                        <p> <span id="errors" style="color: red"></span></p>
                        <br>
                        <input type="file" class="form-control" id="file_id">
                        <br>
                        <button class="btn-block btn-danger" id="btn_id">提交</button>
                    </div>
                </div>

            </div>


        </div>
    </div>




{% endblock %}

{% block js %}
    <script>

        $('#btn_id').click(function () {
            let name = $('#name_id').val()
            let file =$('#file_id')[0].files[0]
            let formdata = new FormData()
            formdata.append('name',name)
            formdata.append('file',file)
            $.ajax({
                url:'',
                type:'post',
                data:formdata,
                contentType:false,
                processData:false,
                success:function (array) {
                    if(array.code===100){
                       alert(array.msg)
                        window.location.reload()
                    } else if(array.code===200)
                    {
                       alert(array.msg)
                    } else if(array.code===500){
                        alert(array.msg)
                    }

                }
            })

        });



        //鼠标获取焦点时，错误信息不显示了。
        $('#id_confirm_pwd').focus(function () {
            $('#error').text('')

        })


    //修改密码的ajax请求

    $('#id_editer').click(function () {

        let old_pwd = $('#id_old_pwd').val()
        let new_pwd = $('#id_new_pwd').val()
        let comfir_pwd = $('#id_confirm_pwd').val()

        $.ajax({
            url:'/app01/set_password/',
            type: 'post',
            data:{'old_pwd':old_pwd,'new_pwd':new_pwd,'confirm_pwd':comfir_pwd},
            success:function (attr) {
                if(attr.code===1000){
                    alert(attr.msg)
                    window.location.reload()
                } else if(attr.code===2000){
                    $('#error').text(attr.msg)
                }else  if(attr.code===3000){
                    $('#error').text(attr.msg)
                }
            }
        })


    })


    </script>

{% endblock %}